
<div class="main_bd">

    <div class="panel panel_overview">
        <div class="panel__hd">
            <h3 class="panel__title">资金变动</h3></div>
        <div class="panel__bd">

            <!--<div class="filter-box">-->
                <!--<a href="/group/select" class="btn btn_primary">新建拼团</a>-->
            <!--</div>-->
            <table class="list-box cell-border hover stripe" id="Table1">


                <tfoot>

                </tfoot>
            </table>
        </div>
    </div>
</div>
<script>

    function getType(type) {

        if(type==1)return '商城销售'
        if(type==2)return '提现'
        if(type==3)return '分销'
        if(type==4)return '充值'
        return '数据异常';//万一还有其他的呢
    }


    $(function(){



        window.grid = $('#Table1').DataTable({
            serverSide: true,
            paging: true,//开启分页
            lengthMenu: [ //自定义分页长度
                [ 20, 50, 100 ],
                [ '20 页', '50 页', '100页' ]
            ],
            columns: [
                {"title": "记录编号", 'data': 'id',width: "80px"},
                {"title": "变动原因", 'data': 'type',width: "200px"},
                {"title": "变动时间", 'data': 'create_time'},
                {"title": "变动前余额", 'data': 'before_total_amount',"defaultContent":"0"},
                {"title": "变动金额", 'data': 'amount'},
                {"title": "变动后余额", 'data': 'after_total_amount'},
                {"title": "说明", 'data': 'content'},
            ],
            "createdRow": function (row, data, index) {
                // console.log(data.validate)
                //
                // $('td', row).eq(-1).append($(tmpl));

            },
            "ajax": {
                url: "/user/amountRecord",
                type: "POST",
                data: function (d) {
                    //删除多余请求参数
                    for(var key in d){
                        if(key.indexOf("columns")==0||key.indexOf("order")==0||key.indexOf("search")==0){ //以columns开头的参数删除
                            delete d[key];
                        }
                    }
                    var searchParams= {
                        page:d.draw,
                        size:d.length,
                    };
                    //附加查询参数
                    if(searchParams){
                        $.extend(d,searchParams); //给d扩展参数
                    }
                },
                dataType : "json",
                "dataSrc": function ( json ) {
                    json.data.map(function(rows){
                        // rows.type
                        rows.type = getType(rows.type)

                        if(rows.action==1){
                            rows.amount = '+'+rows.amount;
                        }else{
                            rows.amount = '-'+rows.amount;
                        }
                    })

                    return json.data;
                },
                dataFilter: function (json) {
                    //json是服务器端返回的数据
                    json = JSON.parse(json);
                    console.log(json)
                    var returnData = {};
                    // returnData.draw = json.data.current_page;
                    returnData.recordsTotal = json.data.total;//返回数据全部记录
                    returnData.recordsFiltered = json.data.total;//后台不实现过滤功能，每次查询均视作全部结果
                    returnData.data = json.data.data;//返回的数据列表
                    return JSON.stringify(returnData);//这几个参数都是datatable需要的，必须要
                }
            },
            oLanguage:{ // 国际化配置
                "sProcessing" : "正在获取数据，请稍后...",
                "sLengthMenu" : "显示 _MENU_ 条",
                "sZeroRecords" : "没有找到数据",
                "sInfo" : "从 _START_ 到  _END_ 条记录 总记录数为 _TOTAL_ 条",
                "sInfoEmpty" : "记录数为0",
                "sInfoFiltered" : "(全部记录数 _MAX_ 条)",
                "sInfoPostFix" : "",
                "sSearch" : "查询",
                "sUrl" : "",
                "oPaginate" : {
                    "sFirst" : "第一页",
                    "sPrevious" : "上一页",
                    "sNext" : "下一页",
                    "sLast" : "最后一页"
                }
            }
        });


    })


</script>